<?php

require_once ('../../libraryfiles/config.php');
$include = '
<script type="text/javascript" src="' . base_url . 'js/action.js"></script>
<script type="text/javascript" src="' . base_url . 'js/common.js"></script>
<script type="text/javascript" src="' . base_url . 'libraryfiles/js_global.php"></script>

<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
';
$view = isset($_GET ['view']) ? $_GET ['view'] : '';
switch ($view) {
    case 'delete' :
        if (isset($_GET ['view']) && $_GET ['view'] == "delete") {
            $ids = $_GET ['id'];
            $delete_product = "DELETE FROM tblproduct WHERE id='" . $ids . "'";
            $sql_image = mysql_query("SELECT *FROM tblimage WHERE product_id='" . $ids . "'");
            while ($imgLinks = mysql_fetch_object($sql_image)) {
                if (file_exists(S_S_IMAGES_DIR . $imgLinks->images)) {
                    unlink(S_S_IMAGES_DIR . $imgLinks->images);
                }
                if (file_exists(S_S_IMAGES_DIR . 'thumb/' . $imgLinks->images)) {
                    unlink(S_S_IMAGES_DIR . 'thumb/' . $imgLinks->images);
                }
            }

            mysql_query("DELETE FROM tblimage WHERE product_id='" . $ids . "'");
            $delete_if = mysql_query($delete_product);
            if ($delete_if) {
                header('Location: ' . base_url . 'account/product/index.php?message=del');
            }
        }
    case 'add' :
        if (isset($_GET ['id'])) {
            $id = (int) $_GET ['id'];
        } else if (isset($_POST ['id'])) {
            $id = $_POST ['id'] [0];
        }
        else
            $id = 0;

        $content = 'add.php';
        break;

    case 'edit' :
        if (isset($_GET ['id'])) {
            $id = (int) $_GET ['id'];
        } else if (isset($_POST ['id'])) {
            $id = $_POST ['id'] [0];
        }
        else
            $id = 0;

        $content = 'add.php';
        break;

    case 'addexist' :
        if (isset($_GET ['id'])) {
            $id = (int) $_GET ['id'];
        } else if (isset($_POST ['id'])) {
            $id = $_POST ['id'] [0];
        }
        else
            $id = 0;

        $content = 'formaddexist.php';
        break;

    case 'editexist' :
        if (isset($_GET ['id'])) {
            $id = (int) $_GET ['id'];
        } else if (isset($_POST ['id'])) {
            $id = $_POST ['id'] [0];
        }
        else
            $id = 0;

        $content = 'formeditexist.php';
        break;

    case 'publish' :
        if (isset($_GET ['id']) && (int) $_GET ['id'] > 0) {
            $id = (int) $_GET ['id'];
        } else {
            header('Location: index.php');
            exit();
        }

        if (isset($_GET ['pharm_id']) && (int) $_GET ['pharm_id'] >= 0) {
            $phar_id = (int) $_GET ['pharm_id'];
        }

        if (isset($_GET ['publish']) && (int) $_GET ['publish'] >= 0 && (int) $_GET ['publish'] <= 1) {
            $publish = (int) $_GET ['publish'];
        } else {
            header('Location: index.php');
            exit();
        }

        // Statement to publish/unpublish User
        publishPro('tblproduct_in_pharmacy', $publish, $id, $phar_id);

        header("Location: index.php?" . getAllGetParams(array(
                    'view',
                    'id',
                    'publish'
        ))); // page=".$page."&");
        exit();
        break;
    default :
        $content = 'list.php';
        break;
}
// require_once TMP_ADMIN_PATH;
require_once TMP_USER_PATH;
?>
